package com.atguigu.ssyx.product.service.impl;

import com.atguigu.ssyx.model.product.SkuImage;
import com.atguigu.ssyx.product.mapper.SkuImageMapper;
import com.atguigu.ssyx.product.service.SkuImageService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 杨林
 * @create 2023-07-25 10:33 星期二
 * description:
 */
@Service
public class SkuImageServiceImpl extends ServiceImpl<SkuImageMapper, SkuImage> implements SkuImageService {

    @Autowired
    SkuImageMapper skuImageMapper;
    
    /**
     * 根据skuId获取所有的图片信息
     * @param id
     * @return
     */
    @Override
    public List<SkuImage> getListBySkuId(Long id) {
        LambdaQueryWrapper<SkuImage> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SkuImage::getSkuId,id);
        List<SkuImage> skuImages = skuImageMapper.selectList(wrapper);
        return skuImages;
    }


    /**
     * 根据skuId删除图片信息
     * @param id
     */
    @Override
    public void removeSkuImageBySkuId(Long id) {
        LambdaQueryWrapper<SkuImage> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SkuImage::getSkuId,id);
        skuImageMapper.delete(wrapper);
    }


    /**
     * 根据skuIds批量删除商品图片信息
     * @param ids
     */
    @Override
    public void removeSkuImageByIds(List<Long> ids) {
        LambdaQueryWrapper<SkuImage> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(SkuImage::getSkuId,ids);
        skuImageMapper.delete(wrapper);
    }
}
